<?php

class Moption_email extends TST_Model {

    protected $table_category = "category";
    protected $table_option_email = "option_email";
    protected $selected_columns = "*";

    function Moption_email() {
        parent::TST_Model();
    }

    public function getEmailAll($status = AppContants::ACTIVE_STATUS) {
        $sql = "SELECT {$this->selected_columns} 
                FROM {$this->table_option_email}
                WHERE status = ?
                ";
        return $this->query_array($sql, $status);
    }

    public function getRowsByCategoryId($language, $id, $status = AppContants::ACTIVE_STATUS) {
        $sql = "SELECT col 
                FROM {$this->table_option_menu}
                WHERE status = ?
                AND   category_id = ? 
                AND   language = ?
                ORDER BY in_order";

        return $this->query_array($sql, array($status, $id, $language));
    }

    public function getParentIdCategory($language, $id, $status) {
        $sql = "SELECT {$this->selected_columns} 
                FROM {$this->table_categories}
                WHERE status = ?
                AND   id = ? 
                AND   language = ?                
                ORDER BY in_order, name";

        return $this->query_row($sql, array($status, $id, $language));
    }

//for Admin ---------------------------------------------------------------
    public function getRowsAll($language) {
        $sql = "SELECT {$this->selected_columns}
                FROM {$this->table_option_email}
                WHERE status NOT LIKE 'delete'
                AND   language = ?
                ORDER BY in_order";
        return $this->query_array($sql,$language);
    }

    public function getEmailById($language, $id) {
        $sql = "SELECT {$this->selected_columns} 
                FROM {$this->table_option_email}
                WHERE id = ? 
                AND   language = ?
                ";

        return $this->query_row($sql, array($id, $language));
    }

    public function update($id, $data) {
        $where = "id = {$id}";
        $sql = $this->db->update_string($this->table_option_email, $data, $where);
        return $this->db->query($sql);
    }

    public function addNew($data) {
        $this->db->insert($this->table_option_email, $data);
        return $this->db->insert_id();
    }

    public function delete($id) {
        $data = array(
            'status' => 'delete'
        );
        $where = "id = {$id}";
        $sql = $this->db->update_string($this->table_option_email, $data, $where);
        return $this->db->query($sql);
    }

}
